<template>
	<view class="detail-contanier" v-if="isLoading">
		<view class="head-btn-name">
			<view class="icon-name">
				<!-- 待支付 -->
				<block v-if="orderState==2">
					<view class="name">订单待支付</view>
				</block>
				<!-- 待发货 -->
				<block v-else-if="orderState==1">
					<view class="name">订单待发货</view>
				</block>
				<!-- 待收货 -->
				<block v-else-if="orderState==3">
					<view class="name">订单待收货</view>
				</block>
				<!-- 已退款 -->
				<block v-else-if="orderState==-3">
					<view class="name">订单已退款</view>
				</block>
				<!-- 已完成 -->
				<block v-else-if="orderState==5">
					<view class="name">订单已完成</view>
				</block>
				<!-- 已取消/待取消 -->
				<block v-else-if="orderState==4">
					<view class="name">订单已取消:</view>
				</block>
			</view>
		</view>
		<view class="module address-module">
			<template v-if="order.deliveryType==10">
				<view class="title">收货地址：</view>
				<view class="name-phone">
					{{order.address.name}} {{order.address.phone}}
				</view>
				<view class="address-detail">{{order.address.addressName}}{{order.address.detail}}</view>
			</template>
			<template v-else>
				<view class="title">自提地址：</view>
				<view class="name-phone">
					{{order.yoshopSelfPoint.name}} {{order.yoshopSelfPoint.phone}}
				</view>
				<view class="address-detail">{{order.yoshopSelfPoint.address}}</view>
			</template>
		</view>
		<view class="module ziti-qrcode-content" v-if="order.deliveryType==20">
			<view class="title">核验码</view>
			<view class="image-c">
				<image class="image" :src="initImageUrl(order.qrCodeUrl)" mode="aspectFill"></image>
			</view>
		</view>
		<view class="module goods-module">
			<unt-goods-detail :data="order.orderGoodsList" modal="order"></unt-goods-detail>
		</view>
		<view class="module order-module">
			<view class="item">
				<text class="item-name">订单编号</text>
				<text class="item-content">{{order.orderNo}}</text>
			</view>
			<view class="item">
				<text class="item-name">下单时间</text>
				<text class="item-content">{{order.createTime}}</text>
			</view>
			<view class="item message">
				<text class="item-name">买家留言</text>
				<text class="item-content">{{order.buyerRemark||'---'}}</text>
			</view>
			<view class="item">
				<text class="item-name">订单金额</text>
				<text class="item-content">¥ {{order.orderPrice}}</text>
			</view>
			<view class="item">
				<text class="item-name">优惠劵抵扣</text>
				<text class="item-content">-¥{{order.couponMoney}}</text>
			</view>
			<view class="item">
				<text class="item-name">运费</text>
				<text class="item-content">-¥{{order.expressPrice}}</text>
			</view>
			<view class="solids-pay">
				<view class="text">实付款</view>
				<text class="price">¥ {{order.payPrice}}</text>
			</view>
		</view>
		<!-- <view class="bottom-fixed">
			<view class="btn-group bottom-fixed">
				<view class="item-btn goods-refund">申请售后</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	import Config from '@/core/config'
	import * as Order from '@/api/order/index.js'
	export default {
		data() {
			return {
				isLoading: false,
				options: {},
				order: {}
			}
		},
		onLoad(options) {
			this.options = options;
			this.getOrderDetail();
		},
		methods: {
			getOrderDetail() {
				const id = this.options.orderId;
				Order.detail({
					orderId: id
				}).then(res => {
					this.order = res.data;
					this.isLoading = true;
				}).catch(err => err)
			},
		},
		computed: {
			initImageUrl(){
				return function(val){
					return Config.get('apiUrl')+val;
				}
			},
			orderState() {
				const v = this.order;
				if (v.orderStatus == 10 && v.deliveryStatus == 10 && v.payStatus != 10) {
					return 1;
				} else if (v.orderStatus == 10 && v.payStatus == 10) {
					return 2;
				} else if (v.orderStatus == 10 && v.deliveryStatus == 20 && v.refundStatus != "SUCCESS") {
					return 3;
				} else if (v.orderStatus == 10 && v.refundStatus == "SUCCESS") {
					return -3;
				} else if (v.orderStatus == 20) {
					return 4;
				} else if (v.orderStatus == 30) {
					return 5;
				}
			}
		},
	}
</script>
<style>
	page {
		background: #F0F0F0;
	}
</style>
<style lang="scss" scoped>
	.detail-contanier {
		position: relative;
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.head-btn-name {
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 40rpx;

			.icon-name {
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 30rpx;

				.name {
					font-weight: bold;
					font-size: 40rpx;

					.image {
						width: 160rpx;
						height: 160rpx;
					}
				}
			}
		}

		.address-module {
			margin-top: -20px;

			.title {
				font-size: 28rpx;
				font-weight: bold;
				margin-bottom: 20rpx;
				color: #08B61F;
			}

			.address-detail {
				color: #999;
				margin-top: 10rpx;
			}
		}

		.module {
			width: 95%;
			margin-bottom: 20rpx;
			box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
			background: #fff;
			padding:30rpx 20rpx;
			border-radius: 25rpx;
			font-size: 28rpx;

			.item {
				display: flex;
				justify-content: space-between;
				margin-bottom: 15rpx;

				.item-name {
					color: #999;
				}
			}

			.solids-pay {
				display: flex;
				justify-content: flex-end;
				margin-top: 25rpx;
				border-top: 1px solid #f5f5f5;
				padding-top: 20rpx;

				.price {
					margin-left: 15rpx;
					color: #FC483C;
				}
			}

			.message {
				padding-bottom: 15rpx;
				border-bottom: 1px solid #f0f0f0;
			}
		}
		.goods-module{
			padding: 20rpx 10rpx;
		}
		.ziti-qrcode-content{
			padding: 30rpx;
			.title{
				font-weight: bold;
			}
			.image-c{
	    text-align: center;
					.image{
						width: 150px;
						height: 150px;
					}
			}
		}
		.btn-group {
			width: 100%;
			display: flex;
			justify-content: flex-end;
			padding: 20rpx;

			.item-btn {
				margin-left: 20rpx;
				padding: 10rpx 30rpx;
				background: #fff;
				border-radius: 100px;
				font-size: 28rpx;
				letter-spacing: 5rpx;
				border: 1px solid #c1c1c1;
			}
		}
	}
</style>